package org.exercise9.memorandum;

/**
 * @author Stranger
 * @version 1.0
 * @description: TODO
 * @date 2022/12/20 16:35
 */
public class Player {

    private PlayerStatus originStatus;

    public Player(String weapons, int health, int skills, int defense) {
        this.originStatus = new PlayerStatus(weapons, health, skills, defense);
    }

    public void fight() {
        originStatus.health--;
        originStatus.skills++;
        originStatus.defense--;
    }

    public void recover(Status playerStatus) {
        this.originStatus = (PlayerStatus) playerStatus;
    }

    public Status getOriginStatus() {
        return originStatus.clone();
    }

    @Override
    public String toString() {
        return String.format("Player{weapons:%s, health:%d, skills:%d, defense:%d}", this.originStatus.weapons, this.originStatus.health, this.originStatus.skills, this.originStatus.defense);
    }

    private class PlayerStatus implements Status {

        private String weapons;

        private int health;

        private int skills;

        private int defense;

        public PlayerStatus(String weapons, int health, int skills, int defense) {
            this.weapons = weapons;
            this.health = health;
            this.skills = skills;
            this.defense = defense;
        }


        @Override
        public Status clone() {
            return new PlayerStatus(this.weapons, this.health, this.skills, this.defense);
        }
    }

}
